const util = require("../../../../utils/util.js")
const api = require("../../../../wxapi/config.js")
Page({
	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {
		return {
			title: '影视行业大数据',
			path: '/pages/index/RankingList/boxoffice/boxoffice'
		}
	},
	/**
	 * 页面的初始数据
	 */
	data: {
    cityActive: '全国',
    boxofficeList: [],
    minDate: new Date(2015, 4, 1).getTime(),
    maxDate: new Date().getTime(),
    currentDate: new Date().getTime(),
    currentDateStr: util.formatDate(new Date()),
    previous: false,
    next: true,
		isShowPicker: false,
		isloading: true,
		skeleton: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
  
	},
  getData(city, date) {
		this.setData({
			isloading: true
		})
    api.getBoxofficeList({city: city, rq: date}).then((res) => {
      if (res.data.length !== 0) {
        this.setData({
					boxofficeList: res.data,
					isloading: false
        })
      } else {
				this.setData({
					boxofficeList: [],
					isloading: false
				})
      } 
    })
  },

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
    // let city = this.data.cityActive === '全国' ? '' : this.data.cityActive
    this.getData(this.data.cityActive, this.data.currentDateStr)
	},

  // 去选择城市页
  toSelectCityPage() {
    wx.navigateTo({
      url: '/component/city-list/index',
    })
  },
  // 显示日期选择器组件
  isShowPicker() {
    this.setData({
      isShowPicker: true
    })
  },
  // 取消隐藏选择场次座位组件
  hideDatepicker() {
    this.setData({
      isShowPicker: false
    })
  },

  // 选择日期后点击【确认】的响应事件
  changeDate(event) {
    const date = new Date(event.detail);
    this.setData({
      isShowPicker: false,
      currentDate: event.detail,
      currentDateStr: util.formatDate(date)
    })
    // let city = this.data.cityActive === '全国' ? '' : this.data.cityActive
    this.getData(this.data.cityActive, this.data.currentDateStr)
  },
  // 显示日期选择组件
  showDatetimeOpt() {
    this.setData({
      isShowPicker: true
    })
  },
  // 取消日期选择组件
  hideDatetimeOpt() {
    this.setData({
      isShowPicker: false
    })
  },

	
	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
    // let city = this.data.cityActive === '全国' ? '' : this.data.cityActive
    this.getData(this.data.cityActive, this.data.currentDateStr)
	}
})